-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: reduce fs-extra
usage in scripts/
#56917
Conversation
Tests Passed |
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
|
@@ -1,7 +1,8 @@ | |||
import os from 'os' | |||
import path from 'path' | |||
import execa from 'execa' | |||
import fs from 'fs-extra' | |||
import fs from 'fs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use promises here instead of sync funcs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with promises-based fs APIs, the main thread is still blocked by await
in the single-threaded script, effectively idling (install-native.mjs
is a single-thread script, invoked by pnpm run
).
fs async APIs are favored when the main thread should not be blocked, such as a web server managing several incoming requests, or using Promise.all
to parallelize tasks sent in the Node.js's libuv worker pool. But we are not doing those in install-native.mjs
.
Generally, fs sync APIs are faster (up to 40%) than async APIs (They don't require creating Promise objects, which alleviates GC pressure and avoids extra ticks).
The PR follows #56536 and #56491, replacing
fs-extra
usages inside thescripts/
folder.Note that the
copy
andhaven't been replaced yet. Currently, there is no better recursive copy (lightweight, promise-based, Node.js built-inmove
copyFile
API-based, support thefilter
option) library alternative available on npm,and Node.js built-in.fs.rename
doesn't supportoverwrite
The PR also replaces many async fs API usage with their sync versions.
cc @wbinnssmith